package servlet;

import eneity.News;
import service.UserManage;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

public class topicInfoServlet extends HttpServlet {
    UserManage userManage=new UserManage();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        int pageindex=0;
        int currenPage=0;
        if (req.getParameter("pageindex")==null){
            pageindex=0;
            currenPage=0;
        }else {
            currenPage= (Integer.parseInt(req.getParameter("currenPage"))-1);
            pageindex= Integer.parseInt(req.getParameter("pageindex"));
        }
        List list = userManage.getNews(pageindex);
        List topiclist=userManage.getTopic();
        ;
        if ((req.getSession().getAttribute("username")!=null)){
            req.setAttribute("list",list);
            req.setAttribute("topiclist",topiclist);
            req.setAttribute("currenPage",currenPage);
            req.setAttribute("username",(req.getSession().getAttribute("username")));
            req.getRequestDispatcher("adminPage.jsp").forward(req,resp);
        }
        else {
            resp.sendRedirect("index.jsp");
        }

    }
}
